//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    // userType: "",
    // // 上拉加载数组
    // onReachBottomData: [],
    // resultMsg: "",
    state: "",
    // // 页数
    active: 1,
    ComplaintType: 0,//0投诉1被投诉
    pageIndex: 1,
    listData: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var uid = wx.getStorageSync('uid');
    // var userType = this.data.userType;
    // userType = wx.getStorageSync('userType');
    this.setData({
      uid: uid,
      // userType: userType,
    })
    this.GetMyBeComplained(this.data.ComplaintType);
    // console.log("method=GetMyBeComplained&ComplaintType=0&UID=" + this.data.uid + "&PageSize=10&PageIndex=" + this.data.pageIndex);
    // wx.request({
    //   url: baseJs.api + baseJs.encryUrl("method=GetMyBeComplained&ComplaintType=0&UID=" + this.data.uid + "&PageSize=10&PageIndex=" + this.data.pageIndex),
    //   success: function (res) {
    //     var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
    //     console.log(json);
    //   }
    // })
  },
  // 投诉记录
  tsjilu() {
    var that = this
    that.setData({
      active: true,
      ComplaintType: 0
    })
    var complaintType = that.data.ComplaintType
    this.GetMyBeComplained(complaintType)
    console.log("投诉");
    // console.log("method=GetMyBeComplained&ComplaintType=0&UID=" + that.data.uid + "&PageSize=10&PageIndex=" + that.data.pageIndex);
    // wx.request({
    //   url: baseJs.api + baseJs.encryUrl("method=GetMyBeComplained&ComplaintType=0&UID=" + that.data.uid + "&PageSize=10&PageIndex=" + that.data.pageIndex),
    //   success: function (res) {
    //     var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
    //     console.log(json);
    //   }
    // })
  },
  // 被投诉记录
  Btsjilu() {
    var that = this
    that.setData({
      active: false,
      ComplaintType: 1
    })
    var complaintType = that.data.ComplaintType
    this.GetMyBeComplained(complaintType)
    console.log("被投诉");
    // console.log("method=GetMyBeComplained&ComplaintType=1&UID=" + that.data.uid + "&PageSize=10&PageIndex=" + that.data.pageIndex);
    // wx.request({
    //   url: baseJs.api + baseJs.encryUrl("method=GetMyBeComplained&ComplaintType=1&UID=" + that.data.uid + "&PageSize=10&PageIndex=" + that.data.pageIndex),
    //   success: function (res) {
    //     console.log(JSON.parse(baseJs.decryUrl(res.data)));
    //     var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
    //     console.log(json);
    //   }
    // })
  },

  // 获取投诉记录
  GetMyBeComplained(complaintType) {
    console.log(complaintType);
    var that = this;
    var uid = this.data.uid;
    var pageIndex = this.data.pageIndex;
    var listData = this.data.listData;
    wx.showLoading({
      title: '加载中',
    })
    console.log("method=GetMyBeComplained&ComplaintType=" + complaintType + "&UID=" + uid + "&PageSize=10&PageIndex=" + pageIndex);
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetMyBeComplained&ComplaintType=" + complaintType + "&UID=" + uid + "&PageSize=10&PageIndex=" + pageIndex),
      success: function (res) {
        console.log(JSON.parse(baseJs.decryUrl(res.data)));
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        console.log(json);
        
        if (json.length == 10) {
          that.setData({
            listData: json,
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            listData: json,
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            listData: json,
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            listData: json,
            state: 'noMore',
          })
        }
        wx.hideLoading();
      }
    })
  },
 



  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.GetMyBeComplained(this.data.ComplaintType)
  },


})